﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class web_SanDefault : System.Web.UI.Page
{
    public string masan;
    public string tensan;
    public string soVLT;
    public string soNTV;
    Common comm = new Common();
    SanGDVL sanComm = new SanGDVL();
    public DataTable dtt_san;
    protected void Page_Load(object sender, EventArgs e)
    {
        masan = Request.QueryString["sid"];
        
        string sql = "SELECT * FROM sangiaodich "
                   + " inner join TrungTamViecLam on TrungTamViecLam.ma_trung_tam = sangiaodich.ma_trung_tam "
                   + " WHERE  ma_san =  '" + masan + "'";
        dtt_san = comm.getDataTable(sql);

        if (dtt_san.Rows.Count == 0) {
            Response.Redirect("SanNotFound.aspx");
        
        }else  if (Convert.ToInt32(dtt_san.Rows[0]["kich_hoat"]) == 1) {

            tensan = "ĐANG MỞ";
            soVLT = sanComm.SoLuongVLT(masan);
            soNTV = sanComm.SoLuongNTV(masan);
            LoadGroupByNganhnghe();
            LoadTP();
            LoadGroupByChucDanh();
        }

    }
    void LoadGroupByNganhnghe()
    {
        cbb_nganh.DataSource = comm.ExeceuteDataset("select A.ma_chuyen_mon, A.ten_chuyen_mon, B.total from DanhMuc_chuyen_mon as A right outer join (select count(A.ma_chuyen_mon) as total, A.ma_chuyen_mon from ViecLamTrong_yeu_cau_chuyen_mon as A where A.kich_hoat = 1 group by A.ma_chuyen_mon) as B on A.ma_chuyen_mon = B.ma_chuyen_mon");
        cbb_nganh.DataValueField = "ma_chuyen_mon";
        cbb_nganh.DataTextField = "ten_chuyen_mon";
        cbb_nganh.DataBind();
        cbb_nganh.Items.Add(new ListItem("Tất cả", ""));
        cbb_nganh.SelectedValue = "";
    }
    void LoadGroupByChucDanh()
    {
        cbb_nganh_ntv.DataSource = comm.ExeceuteDataset("select * from DanhMuc_chuc_danh where ma_chuc_danh in (	select chuc_danh_mong_muon from nguoitimviec_ho_so 	where ma_ho_so in 	(		select ma_ho_so_tim_viec from SanGiaoDich_nguoi_tim_viec 		where ma_san = '"+masan+"'	))");
        cbb_nganh_ntv.DataValueField = "ma_chuc_danh";
        cbb_nganh_ntv.DataTextField = "ten_chuc_danh";
        cbb_nganh_ntv.DataBind();
        cbb_nganh_ntv.Items.Add(new ListItem("Tất cả", ""));
        cbb_nganh_ntv.SelectedValue = "";
    }
    protected void LoadTP()
    {
        string sqlComm = "Select ma_dia_chi, ten_dia_chi from DanhMuc_dia_chi where muc=0 order by ten_dia_chi ";
        cbb_dia_phuong.DataSource = comm.ExeceuteDataset(sqlComm);
        cbb_dia_phuong.DataValueField = "ma_dia_chi";
        cbb_dia_phuong.DataTextField = "ten_dia_chi";
        cbb_dia_phuong.DataBind();
        cbb_dia_phuong.Items.Add(new ListItem("Tất cả", ""));
        cbb_dia_phuong.SelectedValue = "";
        cbb_diaphuong_ntv.DataSource = comm.ExeceuteDataset(sqlComm);
        cbb_diaphuong_ntv.DataValueField = "ma_dia_chi";
        cbb_diaphuong_ntv.DataTextField = "ten_dia_chi";
        cbb_diaphuong_ntv.DataBind();
        cbb_diaphuong_ntv.Items.Add(new ListItem("Tất cả", ""));
        cbb_diaphuong_ntv.SelectedValue = "";
    }
}
